package com.woniu.fly.fairmall.db.service;

import com.woniu.fly.fairmall.db.dao.FairmallSystemConfigDao;
import com.woniu.fly.fairmall.db.entity.FairmallSystem;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Discription: 系统配置参数服务层
 * @author YangChunhai
 * @created 2020/3/19 11:04
 */
@Service
public class FairmallSystemConfigService {

    @Resource
    private FairmallSystemConfigDao fairmallSystemConfigDao;

    public Map<String, String> queryAllConfig(){
        List<FairmallSystem> fairmallSystems = fairmallSystemConfigDao.queryAll();
        Map<String, String> systemConfigs = new HashMap<>();
        for (FairmallSystem system : fairmallSystems) {
            systemConfigs.put(system.getKeyName(), system.getKeyValue());
        }
        return systemConfigs;
    }

    public void addConfig(String key, String value) {
        FairmallSystem system = new FairmallSystem();
        system.setKeyName(key);
        system.setKeyValue(value);
        system.setAddTime(LocalDateTime.now());
        system.setUpdateTime(LocalDateTime.now());
        fairmallSystemConfigDao.addConfig(system);
    }
}
